package com.hod.client.reserves;

import java.util.Date;

import com.google.gwt.core.client.GWT;
import com.google.gwt.gears.client.database.DatabaseException;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.Widget;
import com.gwtext.client.core.EventCallback;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.core.Function;
import com.gwtext.client.core.Position;
import com.gwtext.client.data.Record;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.PaddedPanel;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
import com.gwtext.client.widgets.form.ComboBox;
import com.gwtext.client.widgets.form.DateField;
import com.gwtext.client.widgets.form.FieldSet;
import com.gwtext.client.widgets.form.FormPanel;
import com.gwtext.client.widgets.form.Label;
import com.gwtext.client.widgets.form.NumberField;
import com.gwtext.client.widgets.form.TextField;
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
import com.gwtext.client.widgets.grid.AbstractSelectionModel;
import com.gwtext.client.widgets.grid.RowSelectionModel;
import com.gwtext.client.widgets.grid.event.RowSelectionListenerAdapter;
import com.gwtext.client.widgets.layout.ColumnLayout;
import com.gwtext.client.widgets.layout.ColumnLayoutData;
import com.gwtext.client.widgets.layout.FitLayout;
import com.hod.client.HOD;
import com.hod.client.HODScreenManager;
import com.hod.client.backend.orm.client.GearsDataStore;
import com.hod.client.backend.orm.client.GearsQuery;
import com.hod.client.client.Client;
import com.hod.client.client.ClientCRUD;
import com.hod.client.client.ClientRecordset;
import com.hod.client.frontend.AbstractGrid;
import com.hod.client.frontend.CRUD;
import com.hod.client.frontend.HODForm;
import com.hod.client.room.Room;
import com.hod.client.roomtype.RoomType;
import com.hod.client.roomtype.RoomTypeCRUD;
import com.hod.client.roomtype.RoomTypeRecordset;


public class ReservationCRUD extends CRUD {
	
	protected String idRoomType;

	
	public ReservationCRUD() {
		ds = (GearsDataStore) GWT.create(Reservation.class);
		gridPanel = new ReservationGrid(false,ds,"");
	}
	    
	@Override
	protected void buildPanelSearch() {
		// TODO Auto-generated method stub		
		HODScreenManager.clients.createClientPanelSearch(panel,new ComboBoxListenerAdapter() {
			public void onSelect(ComboBox comboBox, Record record, int index) {
				gridPanel.getStore().clearFilter();
				gridPanel.getStore().filter("idClient", record.getAsString("idClient"));
				gridPanel.getSelectionModel().selectFirstRow();
			}
		},
		new EventCallback(){

			@Override
			public void execute(EventObject e) {
				// TODO Auto-generated method stub
				gridPanel.getStore().clearFilter();
			}
			
		});
		
	}

	protected AbstractSelectionModel createSelectionModel() {
		// TODO Auto-generated method stub
		final RowSelectionModel sm = new RowSelectionModel(true);
        sm.addListener(new RowSelectionListenerAdapter() {
        	public void onRowSelect(RowSelectionModel sm, int rowIndex, Record record) {
        		((ReservationFormPanel)formPanel).updateDataControls(record);
        		((ReservationFormPanel)formPanel).setIdClient(record.getAsInteger("idClient"));
            }
        });
        return sm;
	}
	

	@Override
	protected Widget formTabs() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public HODForm createFormPanel() {
		// TODO Auto-generated method stub
		if (formPanel==null) formPanel = new ReservationFormPanel(ds);
	        return formPanel;
	}

	public void setIdClient(int idClient) {
		// TODO Auto-generated method stub
		((ReservationFormPanel)formPanel).setIdClient(idClient);
	}
	
		
	
	

}
